<template>
  <el-card>
    <h1>成绩查询</h1>
    <el-form
      ref="searchFormRef"
      :model="searchForm"
      inline
    >
      <el-form-item>
        <el-select
          v-model="searchForm.sport"
          placeholder="请选择比赛项目"
        >
          <el-option
            v-for="it in xiangmuShuzu"
            :key="it._id"
            :label="it.name"
            :value="it._id"
          />
        </el-select>
      </el-form-item>
   
      <el-form-item>
        <el-button
          type="success"
          @click="searchByXM()"
        >
          查询
        </el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="sportItemList"
      border
    >
      <el-table-column
        align="center"
        prop="sport.name"
        label="比赛项目"
      />
      <el-table-column
        align="center"
        prop="student.stuName"
        label="参赛学生"
      />
      <el-table-column
        align="center"
        prop="student.sex"
        label="性别"
      />
      <el-table-column
        align="center"
        prop="student.parent.className"
        label="班级"
      />
      <el-table-column
        label="成绩"
        align="center"
        width="120px"
        prop="score"
      />
      <el-table-column
        label="积分"
        align="center"
        prop="jf"
      />
      <!-- <el-table-column
        align="center"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            @click="submitJf(scope.row)"
            type="primary"
            size="medium"
          >
            保存
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      stuShuzu: [],
      activeName: "chakanbisai",
      xiangmuShuzu: [],
      searchForm: {
        sport: "",
      },
      sportItemList: [],
    };
  },
  created() {
    this.fetch();
    this.getStu();
    this.getXiangmu();
  },

  methods: {
      async getStu() {
      const rs = await this.$http.get("rest/students");
      if (rs.status !== 200) return;
      this.stuShuzu = rs.data;
      console.log("学生");
      console.log(rs.data);
    },
    async submitJf(row) {
      console.log(row);
      // 录入学生积分
      row.student.stuJf = row.js + row.student.stuJf;
      const rs = await this.$http.put(
        `rest/students/${row.student._id}`,
        row.student
      );
      if (rs.status !== 200) return;
      this.$message.success("成功录入学生积分");
      console.log("学生积分");
      console.log(rs.data);
      // 录入班级积分
      row.student.parent.classJf = row.js + row.student.parent.classJf;
      const rs2 = await this.$http.put(
        `rest/classes/${row.student.parent._id}`,
        row.student.parent
      );
      if (rs2.status !== 200) return;
      this.$message.success("成功录入班级积分");
      console.log("班级积分");
      console.log(rs.data);
      // 录入比赛积分
      const rs1 = await this.$http.put(`rezst/applies/${row._id}`, row);
      if (rs1.status !== 200) return;
      this.$message.success("成功录入比赛积分");
      console.log("比赛积分");
      console.log(rs.data);
    },
    async submitScore(row) {
      console.log(row);
      const rs = await this.$http.put(`rest/applies/${row._id}`, row);
      if (rs.status !== 200) return;
      this.$message.success("成功录入成绩");
    },
    remove(row) {
      this.$confirm(`是否删除报名`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const rs = await this.$http.delete(`rest/applies/${row._id}`);
        rs;
        this.$message({
          type: "success",
          message: "删除成功!",
        });
        this.fetch();
      });
    },
    async fetch() {
      const rs = await this.$http.get("rest/applies");
      this.sportItemList = rs.data;
      console.log("报名列表");
      console.log(rs.data);
    },

    async getXiangmu() {
      const rs = await this.$http.get("rest/sport_items");
      if (rs.status !== 200) return;
      this.xiangmuShuzu = rs.data;
      console.log("项目");
      console.log(rs.data);
    },

    async fenpeizuci() {
      for (var i = 0; i <= this.sportItemList.length; i++) {
        this.$set(this.sportItemList[i].daoci, this.daociShuzu[i]);
        // this.sportItemList[i].daoci =  this.daociShuzu[i]
      }
      console.log("分配完成-------------------------------");
    },
    async searchByXM() {
      const rs = await this.$http.post("sportManage/search", this.searchForm);
      if (rs.status !== 200) return;
      // this.xiangmuShuzu = rs.data;
      this.$message.success('查询比赛成功')
      console.log("比赛查询");
      console.log(rs.data);
      this.sportItemList = rs.data;
    },
  },
};
</script>

<style lang="scss" scoped>
.fiw {
  width: 200px;
}
h1 {
  margin-bottom: 40px;
}
.el-row {
  margin-bottom: 25px;
}
.elrowdy {
  display: flex;
  flex-direction: row-reverse;
}
</style>
